package org.example.cloudapply.controller;

import jakarta.validation.Valid;
import org.example.cloudapply.dto.HandleApplicationDTO;
import org.example.cloudapply.dto.PageDTO;
import org.example.cloudapply.entity.Result;
import org.example.cloudapply.service.AdminApplicationService;
import org.example.cloudapply.vo.AdminApplicationVO;

import com.github.pagehelper.PageInfo;
import org.example.cloudapply.vo.AdminProcessedVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/applications")
public class AdminApplicationController {

    private final AdminApplicationService adminApplicationService;

    public AdminApplicationController(AdminApplicationService adminApplicationService) {
        this.adminApplicationService = adminApplicationService;
    }

    @GetMapping("/pending")
    public Result<PageInfo<AdminApplicationVO>> getPendingApplications(@Valid PageDTO dto) {
        return Result.success(adminApplicationService.getPendingApplications(dto));
    }

    @PostMapping("/handle")
    public Result<?> handleApplication(@Validated @RequestBody HandleApplicationDTO dto) {
        adminApplicationService.handleApplication(dto);
        return Result.success();
    }

    @GetMapping("/processed")
    public Result<PageInfo<AdminProcessedVO>> getProcessedApplications(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        return Result.success(adminApplicationService.getProcessedApplications(page, size));
    }


    @DeleteMapping("/{applyId}")
    public Result<?> deleteProcessedApplication(@PathVariable Integer applyId) {
        adminApplicationService.deleteProcessedApplication(applyId);
        return Result.success();
    }
}